﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Globalization;
using System.Drawing;
using Project.Model;

namespace Project
{


    /// <summary>
    /// Свойство "Методы"
    /// </summary>
    [TypeConverter(typeof(MethodsTypeConverter))]
    public class MethodsType
    {
        private List<Descriptions_DomainModel.Model.Method> methodsF = new List<Descriptions_DomainModel.Model.Method>();

        public List<Descriptions_DomainModel.Model.Method> methods
        {
            get { return methodsF; }
        }

    }

    /// <summary>
    /// Конвертер свойства "Методы"
    /// </summary>
    public class MethodsTypeConverter : TypeConverter
    {

        public override object ConvertTo(ITypeDescriptorContext context,

            System.Globalization.CultureInfo culture, object value, Type destinationType)
        {//This method is used to shown information in the PropertyGrid.

            if (destinationType == typeof(string))
            {

                return ("Список методов, да...");

            }

            return base.ConvertTo(context, culture, value, destinationType);
        }



        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            return TypeDescriptor.GetProperties(typeof(MethodsType),attributes);
        }



        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            
            return new StandardValuesCollection((context.Instance as MethodsType).methods.ToArray());
        }

    }

    public class BooleanTypeConverter : BooleanConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context,
          CultureInfo culture,
          object value,
          Type destType)
        {
            return (bool)value ?
              "Да" : "Нет";
        }

        public override object ConvertFrom(ITypeDescriptorContext context,
          CultureInfo culture,
          object value)
        {
            return (string)value == "Да";
        }
    }

    public class ProjectTypeConverter : TypeConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context,
          CultureInfo culture,
          object value,
          Type destType)
        {
            if (value is ProjectType)
            {
                ProjectType projectType = (ProjectType)value;
                switch (projectType)
                {
                    case ProjectType.Usual:
                        return "Разнодокументный";
                    case ProjectType.CommandList:
                        return "Списки команд";

                }
            }
            return "Разнодокументный";
        }

        public override object ConvertFrom(ITypeDescriptorContext context,
          CultureInfo culture,
          object value)
        {
            string projectTypeName = (string)value;
            switch (projectTypeName)
            {
                case "Разнодокументный":
                    return ProjectType.Usual;
                case "Списки команд":
                    return ProjectType.CommandList;
            }
            return ProjectType.Usual;
        }
    }

    public class DocumentTypeConverter : ExpandableObjectConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
        {
            if (destType == typeof(string) && (value is DocumentType))
            {
                DocumentType dt = (DocumentType)value;
                return dt.Name;
            }
            return null;//base.ConvertTo(context, culture, value, destType);
        }
    }

    public class DocumentTypeEditor : System.Drawing.Design.UITypeEditor
    {
        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e)
        {

            /*            DocumentType dt = ((DocumentType)(e.Value));

                        Bitmap img = (Bitmap)dt.Img;
                        Rectangle destRect = e.Bounds;
                        img.MakeTransparent();

                        e.Graphics.DrawImage(img, destRect);*/
        }
    }
}
